<?php

namespace app\admin\model\curriculum;

use think\Model;

class Test extends Model
{
    // 表名
    protected $name = 'curriculum_test';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    
    // 追加属性
    protected $append = [
        'true_status_text',
        'addtime_text',
        'status_text'
    ];
    

    
    public function getTrueStatusList()
    {
        return ['a' => __('True_status a'),'b' => __('True_status b'),'c' => __('True_status c'),'d' => __('True_status d')];
    }     

    public function getStatusList()
    {
        return ['normal' => __('Normal'),'hidden' => __('Hidden')];
    }     


    public function getTrueStatusTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['true_status']) ? $data['true_status'] : '');
        $list = $this->getTrueStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getAddtimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['addtime']) ? $data['addtime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getStatusTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setAddtimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }


}
